<?php


namespace XinYaTable\Forms\Models;


class EloquentForm extends BaseModel {
    protected $table      = 'sys_forms';
    protected $searchable = [
        'title'
    ];
    
    public function fields() {
        return $this->hasMany(EloquentFormField::class, 'form_id', 'id')
            ->where('is_delete', 0)
            ->select([
                'id',
                'form_id',
                'title',
                'field_name',
                'field_type',
                'props',
                'validate',
                'style',
                'display',
                'searchable',
                'order',
                'show_column'
            ])
            ->orderBy('order')
            ->with('fieldOptions');
    }
    
    /**
     * 获取正在使用的表单
     *
     * @param     $query
     * @param int $id
     *
     * @return mixed
     */
    public function scopeUsingForm($query, $id, $typeFormName = 'table_name') {
        return $query->where($typeFormName, $id)->where('is_using', 1)->where('is_delete', 0);
    }
    
}